import com.alibaba.moco.RedisPoolInstance
import com.alibaba.moco.util.BaseTypeUtil
import groovy.json.JsonSlurper
import org.apache.commons.lang.StringUtils
import redis.clients.jedis.Jedis
import script.GlobalValues
/**
 * 模拟 滴滴 獲取全量城市列表
 * Created by wb-lj240895 on 2016/11/1.
 */
def excute(request){

    Jedis redis = RedisPoolInstance.getRedisClient()
    def params = request.getParameterMap();
    AllCitiesRequest req = BaseTypeUtil.mapToBean(params, AllCitiesRequest.class) as AllCitiesRequest

    //欢行异常判断
    def e = redis.hget(GlobalValues.KEY_EXCEPTION,"cities")
    if (!StringUtils.isBlank(e)) {
        def slurper = new JsonSlurper()
        def eJson = slurper.parseText(e)
        return eJson
    }
    def slurper = new JsonSlurper()
    return slurper.parseText("{\"errno\":0,\"errmsg\":\"SUCCESS\",\"data\":[{\"name\":\"A\",\"cities\":[{\"name\":\"鞍山市\",\"cityid\":64,\"open_zhuanche\":0,\"open_kuaiche\":1},{\"name\":\"安庆市\",\"cityid\":149,\"open_zhuanche\":0,\"open_kuaiche\":1}]},{\"name\":\"B\",\"cities\":[{\"name\":\"北京市\",\"cityid\":1,\"open_zhuanche\":1,\"open_kuaiche\":1},{\"name\":\"保定市\",\"cityid\":62,\"open_zhuanche\":0,\"open_kuaiche\":1}]}]}")
}
public class AllCitiesRequest {
    String client_id    //	string	yes	申请应用时分配的APP_KEY
    String access_token //	string	yes	乘客认证信息
    String timestamp       //	int	yes	时间戳
    String sign         //	string	yes	签名
}